package com.java.comprehensive.arithmetic.programmers;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @program: comprehensive-service
 *
 * @description: 判定是否互为字符重排
 *
 * @author: 窦绍飞
 *
 * @create: 2022-01-19 16:31
 **/
public class CheckPermutation {




	public static boolean checkPermutation(String s1, String s2) {
		Map<Character, Integer> map = new HashMap<Character, Integer>();
		for (int i = 0; i < s1.length(); i++) {
			map.merge(s1.charAt(i), 1, Integer::sum);

		}
		for (int i = 0; i < s2.length(); i++) {
			Integer integer = map.get(s2.charAt(i));
			if (integer == null) {
				return false;
			}
			if (integer.equals(0)) {
				return false;
			}
			map.put(s2.charAt(i), integer - 1);
		}
		return true;
	}

	public static void main(String[] args) {
		String a = "abc";
		String b = "bca";
		checkPermutation(a, b);
	}
}
